package org.itstack;


import org.itstack.model.Order;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

public class OrderProcessorFactory {
    
    private static final Map<String, Consumer<Order>> processors = new HashMap<>();
    
    static {
        // 注册各种订单处理器
        processors.put("VIP_LARGE_ORDER", OrderProcessorFactory::processVipLargeOrder);
        processors.put("NORMAL_LARGE_ORDER", OrderProcessorFactory::processNormalLargeOrder);
        processors.put("VIP_SMALL_ORDER", OrderProcessorFactory::processVipSmallOrder);
        processors.put("NORMAL_SMALL_ORDER", OrderProcessorFactory::processNormalSmallOrder);
        processors.put("URGENT_LARGE_ORDER", OrderProcessorFactory::processUrgentLargeOrder);
        processors.put("URGENT_SMALL_ORDER", OrderProcessorFactory::processUrgentSmallOrder);
        processors.put("DISCOUNT_ORDER", OrderProcessorFactory::processDiscountOrder);
    }
    
    public static void processOrder(Order order, OrderProcessResult result) {
        Consumer<Order> processor = processors.get(result.getResult());
        if (processor != null) {
            processor.accept(order);
        } else {
            System.out.println("未找到对应的订单处理器: " + result.getResult());
        }
    }
    
    // 具体的处理方法
    private static void processVipLargeOrder(Order order) {
        System.out.println("=== VIP大额订单处理: " + order.getId() + " ===");
        System.out.println("订单金额: " + order.getAmount());
        System.out.println("客户等级: " + order.getCustomer().getLevel());
        System.out.println("执行VIP大额订单特殊处理逻辑...");
    }
    
    private static void processNormalLargeOrder(Order order) {
        System.out.println("=== 普通大额订单处理: " + order.getId() + " ===");
        System.out.println("订单金额: " + order.getAmount());
        System.out.println("客户等级: " + order.getCustomer().getLevel());
        System.out.println("执行普通大额订单处理逻辑...");
    }
    
    private static void processVipSmallOrder(Order order) {
        System.out.println("=== VIP小额订单处理: " + order.getId() + " ===");
        System.out.println("订单金额: " + order.getAmount());
        System.out.println("客户等级: " + order.getCustomer().getLevel());
        System.out.println("执行VIP小额订单特殊处理逻辑...");
    }
    
    private static void processNormalSmallOrder(Order order) {
        System.out.println("=== 普通小额订单处理: " + order.getId() + " ===");
        System.out.println("订单金额: " + order.getAmount());
        System.out.println("客户等级: " + order.getCustomer().getLevel());
        System.out.println("执行普通小额订单处理逻辑...");
    }
    
    private static void processUrgentLargeOrder(Order order) {
        System.out.println("=== 紧急大额订单处理: " + order.getId() + " ===");
        System.out.println("订单金额: " + order.getAmount());
        System.out.println("订单类型: " + order.getType());
        System.out.println("执行紧急大额订单处理逻辑...");
    }
    
    private static void processUrgentSmallOrder(Order order) {
        System.out.println("=== 紧急小额订单处理: " + order.getId() + " ===");
        System.out.println("订单金额: " + order.getAmount());
        System.out.println("订单类型: " + order.getType());
        System.out.println("执行紧急小额订单处理逻辑...");
    }
    
    private static void processDiscountOrder(Order order) {
        System.out.println("=== 折扣订单处理: " + order.getId() + " ===");
        System.out.println("订单金额: " + order.getAmount());
        System.out.println("订单类型: " + order.getType());
        System.out.println("执行折扣订单处理逻辑...");
    }
}
